search.parse();

var states = search.get('states');
var grid = search.get('datagrid');
var queryParams = new Form('query-params');

//加载功能按钮
var isrecycle = __param.recycle ? true : false;
var gridutil = new DatagridUtil(grid, {
	funcid : __param.funcid, 
	isRecycle : isrecycle, 
	isOpenDetails : false, 
	validateRules : [
		{methodname : 'viewGood', conditions : [], ismultiple : false}
	],
	validateOptions : {
		fields : ['entitystate']
	}
});

//页面加载完成执行
$(function() {
	states.loadData(sysGlobal.EntityStateForOrderQuery);
	
	grid.url = __ctx + '/order/listData.xhtml';
	grid.load();
});

//查询
function doSearch() {
	grid.load(queryParams.getData());
}

//绘制表格单元格
function ondrawcell(e) {
	var field = e.column.field, record = e.record;
	switch (field) {
		case "orderid":
			e.html = "<span class='grid-cell-link' onclick='viewGood(\"" + record["entityid"] + "\")' title='点击查看采购商品'>" + record["entityid"] + "</span>";
			break;
		case "cybercafe":
			e.html = "<span>" + record["centname"] + "【" + record["cbuslicenseno"] + "】</span><br/><span>" + record["cleader"] + "，" + record["ccontactnumber"] + "</span>";
			break;
		case "supplier":
			e.html = "<span>" + record["sentname"] + "【" + record["sbuslicenseno"] + "】</span><br/><span>" + record["sleader"] + "，" + record["scontactnumber"] + "</span>";
			break;
		case "ordertotal":
			e.html = "<span>" + record[field].toFixed(2) + "</span>";
			break;
		case "confirmtime":
		case "distributetime":
		case "completetime":
			if (record[field]) e.html = "<span>" + new Date(record[field]).format("yyyy-MM-dd HH:mm:ss") + "</span>";
			break;
		case "entitystate":
			e.html = "<span>" + sysGlobal.getEntityStateText(record[field]) + "</span>";
			break;
	}
}

//查看商品
function viewGood(orderid) {
	orderid = orderid.ids || orderid;
	var data = {
		url : __ctx + "/order/goodList.xhtml", 
		title : "查看采购商品", 
		width : 900, 
		height : 600, 
		onload : function(window) {
			window.loadData(orderid);
		}, 
		ondestroy : function(result){
		}
	}
	top.search.popDialog(data);
}
